<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中文名称-图谱" prop="chineseNameKg">
        <el-input
          v-model="queryParams.chineseNameKg"
          placeholder="请输入中文名称-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称" prop="englishName">
        <el-input
          v-model="queryParams.englishName"
          placeholder="请输入英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="英文名称-图谱" prop="englishNameKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.englishNameKg"-->
<!--          placeholder="请输入英文名称-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="国家或地区" prop="countryRegion">-->
<!--        <el-input-->
<!--          v-model="queryParams.countryRegion"-->
<!--          placeholder="请输入国家或地区"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="类型-图谱" prop="typeKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.typeKg"-->
<!--          placeholder="请输入类型-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="目标群体" prop="targetAudience">-->
<!--        <el-input-->
<!--          v-model="queryParams.targetAudience"-->
<!--          placeholder="请输入目标群体"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="目标群体-图谱" prop="targetAudienceKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.targetAudienceKg"-->
<!--          placeholder="请输入目标群体-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="建设单位" prop="constructionEntity">-->
<!--        <el-input-->
<!--          v-model="queryParams.constructionEntity"-->
<!--          placeholder="请输入建设单位"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="建设单位-图谱" prop="constructionEntityKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.constructionEntityKg"-->
<!--          placeholder="请输入建设单位-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="首次出现时间" prop="firstAppearanceTime">-->
<!--        <el-input-->
<!--          v-model="queryParams.firstAppearanceTime"-->
<!--          placeholder="请输入首次出现时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="经费预算" prop="financialBudget">-->
<!--        <el-input-->
<!--          v-model="queryParams.financialBudget"-->
<!--          placeholder="请输入经费预算"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="集成平台" prop="integrationPlatform">-->
<!--        <el-input-->
<!--          v-model="queryParams.integrationPlatform"-->
<!--          placeholder="请输入集成平台"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="附件，允许NULL值" prop="attachment">-->
<!--        <el-input-->
<!--          v-model="queryParams.attachment"-->
<!--          placeholder="请输入附件，允许NULL值"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:equipment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:equipment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:equipment:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:equipment:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="equipmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键，自增" align="center" prop="id" />
      <el-table-column label="中文名称" show-overflow-tooltip  align="center" prop="chineseName" />
      <el-table-column label="中文名称-图谱"  show-overflow-tooltip align="center" prop="chineseNameKg" />
      <el-table-column label="英文名称" show-overflow-tooltip  align="center" prop="englishName" />
      <el-table-column label="英文名称-图谱"  show-overflow-tooltip align="center" prop="englishNameKg" />
      <el-table-column label="国家或地区" show-overflow-tooltip  align="center" prop="countryRegion" />
      <el-table-column label="类型" align="center" prop="type" />
      <el-table-column label="类型-图谱" align="center" prop="typeKg" />
      <el-table-column label="概述" show-overflow-tooltip  align="center" prop="overview" />
      <el-table-column label="作用原理"  show-overflow-tooltip align="center" prop="workingPrinciple" />
      <el-table-column label="调用资源"  show-overflow-tooltip align="center" prop="resourcesUsed" />
      <el-table-column label="影响范围"  show-overflow-tooltip align="center" prop="impactScope" />
      <el-table-column label="目标群体"  show-overflow-tooltip  align="center" prop="targetAudience" />
      <el-table-column label="目标群体-图谱"  show-overflow-tooltip align="center" prop="targetAudienceKg" />
      <el-table-column label="历史版本" show-overflow-tooltip  align="center" prop="historicalVersions" />
      <el-table-column label="建设单位" show-overflow-tooltip  align="center" prop="constructionEntity" />
      <el-table-column label="建设单位-图谱"  show-overflow-tooltip align="center" prop="constructionEntityKg" />
      <el-table-column label="首次出现时间" show-overflow-tooltip  align="center" prop="firstAppearanceTime" />
      <el-table-column label="首次出现时间-图谱" show-overflow-tooltip  align="center" prop="firstAppearanceTimeKg" />
      <el-table-column label="使用实例" show-overflow-tooltip  align="center" prop="usageExamples" />
      <el-table-column label="经费预算" show-overflow-tooltip  align="center" prop="financialBudget" />
      <el-table-column label="集成平台"  show-overflow-tooltip align="center" prop="integrationPlatform" />
      <el-table-column label="附件，允许NULL值"  show-overflow-tooltip align="center" prop="attachment" />
<!--      <el-table-column label="${comment}" align="center" prop="allInfo" />-->
      <el-table-column label="操作"  fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:equipment:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:equipment:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改武器装备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="中文名称" prop="chineseName">
          <el-input v-model="form.chineseName" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="中文名称-图谱" prop="chineseNameKg">
          <el-input v-model="form.chineseNameKg" placeholder="请输入中文名称-图谱" />
        </el-form-item>
        <el-form-item label="英文名称" prop="englishName">
          <el-input v-model="form.englishName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="英文名称-图谱" prop="englishNameKg">
          <el-input v-model="form.englishNameKg" placeholder="请输入英文名称-图谱" />
        </el-form-item>
        <el-form-item label="国家或地区" prop="countryRegion">
          <el-input v-model="form.countryRegion" placeholder="请输入国家或地区" />
        </el-form-item>
        <el-form-item label="类型-图谱" prop="typeKg">
          <el-input v-model="form.typeKg" placeholder="请输入类型-图谱" />
        </el-form-item>
        <el-form-item label="概述" prop="overview">
          <el-input v-model="form.overview" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="作用原理" prop="workingPrinciple">
          <el-input v-model="form.workingPrinciple" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="调用资源" prop="resourcesUsed">
          <el-input v-model="form.resourcesUsed" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="影响范围" prop="impactScope">
          <el-input v-model="form.impactScope" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="目标群体" prop="targetAudience">
          <el-input v-model="form.targetAudience" placeholder="请输入目标群体" />
        </el-form-item>
        <el-form-item label="目标群体-图谱" prop="targetAudienceKg">
          <el-input v-model="form.targetAudienceKg" placeholder="请输入目标群体-图谱" />
        </el-form-item>
        <el-form-item label="历史版本" prop="historicalVersions">
          <el-input v-model="form.historicalVersions" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="建设单位" prop="constructionEntity">
          <el-input v-model="form.constructionEntity" placeholder="请输入建设单位" />
        </el-form-item>
        <el-form-item label="建设单位-图谱" prop="constructionEntityKg">
          <el-input v-model="form.constructionEntityKg" placeholder="请输入建设单位-图谱" />
        </el-form-item>
        <el-form-item label="首次出现时间" prop="firstAppearanceTime">
          <el-input v-model="form.firstAppearanceTime" placeholder="请输入首次出现时间" />
        </el-form-item>
        <el-form-item label="首次出现时间-图谱" prop="firstAppearanceTimeKg">
          <el-input v-model="form.firstAppearanceTimeKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="使用实例" prop="usageExamples">
          <el-input v-model="form.usageExamples" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="经费预算" prop="financialBudget">
          <el-input v-model="form.financialBudget" placeholder="请输入经费预算" />
        </el-form-item>
        <el-form-item label="集成平台" prop="integrationPlatform">
          <el-input v-model="form.integrationPlatform" placeholder="请输入集成平台" />
        </el-form-item>
        <el-form-item label="附件，允许NULL值" prop="attachment">
          <el-input v-model="form.attachment" placeholder="请输入附件，允许NULL值" />
        </el-form-item>
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
              table-type="9"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="9"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="9"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="精翻文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz003'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="9"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEquipment, getEquipment, delEquipment, addEquipment, updateEquipment } from "@/api/business/equipment";
import FileUpload from '@/components/fileUpload_neww.vue'
import { guid } from '@/utils/utils'
import Pictures from '@/components/Pictures'
export default {
  name: "Equipment",
  components: { Pictures,FileUpload },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 武器装备表格数据
      equipmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseName: null,
        chineseNameKg: null,
        englishName: null,
        englishNameKg: null,
        countryRegion: null,
        type: null,
        typeKg: null,
        overview: null,
        workingPrinciple: null,
        resourcesUsed: null,
        impactScope: null,
        targetAudience: null,
        targetAudienceKg: null,
        historicalVersions: null,
        constructionEntity: null,
        constructionEntityKg: null,
        firstAppearanceTime: null,
        firstAppearanceTimeKg: null,
        usageExamples: null,
        financialBudget: null,
        integrationPlatform: null,
        attachment: null,
        allInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        chineseName: [
          { required: true, message: "中文名称不能为空", trigger: "blur" }
        ],
        englishName: [
          { required: true, message: "英文名称不能为空", trigger: "blur" }
        ],
        countryRegion: [
          { required: true, message: "国家或地区不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
        overview: [
          { required: true, message: "概述不能为空", trigger: "blur" }
        ],
        workingPrinciple: [
          { required: true, message: "作用原理不能为空", trigger: "blur" }
        ],
        resourcesUsed: [
          { required: true, message: "调用资源不能为空", trigger: "blur" }
        ],
        impactScope: [
          { required: true, message: "影响范围不能为空", trigger: "blur" }
        ],
        targetAudience: [
          { required: true, message: "目标群体不能为空", trigger: "blur" }
        ],
        historicalVersions: [
          { required: true, message: "历史版本不能为空", trigger: "blur" }
        ],
        constructionEntity: [
          { required: true, message: "建设单位不能为空", trigger: "blur" }
        ],
        firstAppearanceTime: [
          { required: true, message: "首次出现时间不能为空", trigger: "blur" }
        ],
        usageExamples: [
          { required: true, message: "使用实例不能为空", trigger: "blur" }
        ],
        financialBudget: [
          { required: true, message: "经费预算不能为空", trigger: "blur" }
        ],
        integrationPlatform: [
          { required: true, message: "集成平台不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询武器装备列表 */
    getList() {
      this.loading = true;
      listEquipment(this.queryParams).then(response => {
        this.equipmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chineseName: null,
        chineseNameKg: null,
        englishName: null,
        englishNameKg: null,
        countryRegion: null,
        type: null,
        typeKg: null,
        overview: null,
        workingPrinciple: null,
        resourcesUsed: null,
        impactScope: null,
        targetAudience: null,
        targetAudienceKg: null,
        historicalVersions: null,
        constructionEntity: null,
        constructionEntityKg: null,
        firstAppearanceTime: null,
        firstAppearanceTimeKg: null,
        usageExamples: null,
        financialBudget: null,
        integrationPlatform: null,
        attachment: null,
        allInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加武器装备";
      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEquipment(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改武器装备";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEquipment(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEquipment(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除武器装备编号为"' + ids + '"的数据项？').then(function() {
        return delEquipment(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/equipment/export', {
        ...this.queryParams
      }, `equipment_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
